#include "signals.h"
#include <stdio.h>
#include <stdlib.h>
struct signals
{
    unsigned int signal;
    char *describer;
} gf_sg_clooection[] = {
    {SIGINT, "SIGINT"},
    {SIGHUP, "SIGHUP"},
    {SIGABRT, "SIGABRT"},
    {SIGSTOP, "SIGSTOP"},
    {SIGKILL, "SIGKILL"},
    {SIGCONT, "SIGCONT"}

};

int main(int argc, char **argv)
{
    const int limit = sizeof(gf_sg_clooection) / sizeof(struct signals);
    int choice = -1;
    char buf[0x100];

    if (argc == 2)
    {
        choice = parseArg(argv[1], limit);
        if (choice == -1)
        {
            fprintf(stderr, "usage: %s [signum]", *argv);
            fprintf(stderr, "0<signum<%d", limit);
            return 1;
        }
    }
    while (1)
    {
        if (choice != -1)
            break;
        for (int i = 0; i < limit; i++)
            printf("%d:%s\n", i, gf_sg_clooection[i].describer);
        while (1)
        {
            scanf("%s", buf);
            choice = parseArg(buf, limit);
            if (parseArg(buf, limit) != -1)
                break;
            fprintf(stderr, "Huh(%s)?\n", buf);
        }
    }

    fprintf(stderr, "%s selected\n", gf_sg_clooection[choice].describer);
    signal(gf_sg_clooection[choice].signal, catcher);
    // signal(SIGINT, catcher);
    // signal(SIGSTOP, catcher);
    // signal(SIGKILL, catcher);
    // signal(SIGCONT, catcher);
    while (1)
        ;
}